import result from '/@utils/Axios.ts'

// 分类列表
export function category_list(params: any = {}) {
  return result({
    url: '/api/encyclopedia/categories/',
    method: 'get',
    params
  })
}

export function category_create(data: any) {
  return result({
    url: '/api/encyclopedia/categories/',
    method: 'post',
    data
  })
}

export function category_update(id: number, data: any) {
  return result({
    url: `/api/encyclopedia/categories/${id}/`,
    method: 'put',
    data 
  }) 
}

export function category_delete(id: number) {
  return result({
    url: `/api/encyclopedia/categories/${id}/`,
    method: 'delete',
  }) 
}

export function entry_list(params: any = {}) {
  return result({
    url: '/api/encyclopedia/entries/',
    method: 'get',
    params
  })
}

export function entry_create(data: any) {
  return result({
    url: '/api/encyclopedia/entries/',
    method: 'post',
    data
  })
}

export function entry_update(id: number, data: any) {
  return result({
    url: `/api/encyclopedia/entries/${id}/`,
    method: 'put',
    data 
  }) 
}

export function entry_delete(id: number) {
  return result({
    url: `/api/encyclopedia/entries/${id}/`,
    method: 'delete', 
  }) 
}

export function entry_get(id: number) {
  return result({
    url: `/api/encyclopedia/entries/${id}/`,
    method: 'get',
  }) 
}

export function getCategoryTree () {
  return result({
    url: '/api/encyclopedia/categories/tree/',
    method: 'get',
  })
}

export function getHotEntries (params: {limit: number}) {
  return result({
    url: '/api/encyclopedia/entries/hot_ranking/',
    method: 'get',
    params
  }) 
}

export function getLatestEntries (params: {limit: number}) {
    return result({
      url: '/api/encyclopedia/entries/latest/',
      method: 'get',
      params
    }) 
}

export function getHotKeywords (params: {limit: number}) {
    return result({
      url: '/api/encyclopedia/search/hot_keywords/',
      method: 'get',
      params
    }) 
}

export function getSearchHistory () {
    return result({
      url: '/api/encyclopedia/search/history/',
      method: 'get'
    })
}

export function deleteSearchHistory () {
    return result({
      url: `/api/encyclopedia/search/history/`,
      method: 'delete'
    })
}

export function getSearchSuggestions (keyword: string) {
    return result({
      url: '/api/encyclopedia/search/suggestion/',
      method: 'get',
      params: {
        keyword
      }
    }) 
}

export function getSearchResults (params: any) {
    return result({
      url: '/api/encyclopedia/search/',
      method: 'get',
      params
    })
}

export function getEntryAttachments (params: any) {
    return result({
      url: `/api/encyclopedia/attachments/`,
      method: 'get',
      params
    })
}

export function getFavoriteEntries (params: any) {
    return result({
      url: '/api/encyclopedia/favorites/',
      method: 'get',
      params
    }) 
}

export function createFavorite (data: any) {
    return result({
      url: '/api/encyclopedia/favorites/',
      method: 'post',
      data
    }) 
}


export function deleteFavorite (id: number) {
    return result({
      url: `/api/encyclopedia/favorites/${id}/`,
      method: 'delete'
    })
}

export function getRelatedEntries (id: number) {
  return result({
    url: `/api/encyclopedia/entries/${id}/related/`,
    method: 'get'
  })
}

export function uploadAttachment (data: any) {
  return result({
    url: '/api/encyclopedia/attachments/',
    method: 'post',
    timeout: 1000 * 60 * 10,
    data
  })
}

export function deleteAttachment (id: number) {
  return result({
    url: `/api/encyclopedia/attachments/${id}/`,
    method: 'delete'
  })
}

export function entries_view_count (id: number) {
  return result({
    url: `/api/encyclopedia/entries/${id}/view_count/`,
    method: 'post',
  }) 
}